//
//  ZUnpaidView.m
//  DoctorFAQs
//
//  Created by zjq on 17/2/23.
//  Copyright © 2017年 zjq. All rights reserved.
//

#import "ZUnpaidView.h"
@interface ZUnpaidView () <UIGestureRecognizerDelegate>{
    UIImageView * _backView;
    UILabel * _titleLabel;
    UILabel * _conTextLabel;
    UIButton * _goPayBtn;
    UIButton * _canleBtn;
}
@end
@implementation ZUnpaidView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initlizeInterface];
    }
    return self;
}
- (void)initlizeInterface {
    self.backgroundColor = [UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:0.4];// 将背景设置为半透明
    [self makeSubView];
    [self addAllSubView];
    [self makeAllSubViewMasnoy];
    [self addTheTap];
}

- (void)makeSubView {
    _backView = [[UIImageView alloc] init];
    _backView.image = [UIImage imageNamed:@"index_tc"];
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.text = @"温馨提示";
    _titleLabel.font = [UIFont systemFontOfSize:18];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    
    _titleLabel.textColor = MYGREENColor;
    _conTextLabel = [[UILabel alloc] init];
    _conTextLabel.text = @"你还有一单咨询未支付哟，点击前往支付哦";
    _conTextLabel.font = [UIFont systemFontOfSize:20];
    _conTextLabel.textColor = [UIColor blackColor];
    _conTextLabel.numberOfLines = 0;
    _goPayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_goPayBtn setTitle:@"前去支付" forState:UIControlStateNormal];
    [_goPayBtn setTitleColor:MYGREENColor forState:UIControlStateNormal];
    [_goPayBtn addTarget:self action:@selector(gopayAction) forControlEvents:UIControlEventTouchUpInside];
    _goPayBtn.layer.borderWidth = 1.0f;
    _goPayBtn.layer.borderColor = [MYGREENColor CGColor];
    _goPayBtn.layer.cornerRadius = 2.5f;
    _goPayBtn.layer.masksToBounds = YES;
    
    _canleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_canleBtn addTarget:self action:@selector(canleAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)addAllSubView{
    [self addSubview:_backView];
    [self addSubview:_titleLabel];
    [self addSubview:_conTextLabel];
    [self addSubview:_goPayBtn];
    [self addSubview:_canleBtn];
}

- (void)makeAllSubViewMasnoy {
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.offset(280*xsIZE);
        make.height.offset(300*ysIZE);
        make.centerY.equalTo(self);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.top.equalTo(_backView).offset(20*ysIZE);
        make.width.equalTo(_backView).multipliedBy(0.6);
        make.height.offset(18*ysIZE);
    }];
    [_conTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.centerY.equalTo(_backView).offset(-30*ysIZE);
        make.width.equalTo(_backView).multipliedBy(0.95);
        make.height.offset(60*ysIZE);
    }];
    [_goPayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_backView);
        make.height.offset(35*ysIZE);
        make.width.offset(120*xsIZE);
        make.top.equalTo(_conTextLabel.mas_bottom).offset(25*ysIZE);
    }];
    [_canleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_backView);
        make.bottom.equalTo(_backView);
        make.width.offset(30*ysIZE);
        make.height.offset(30*ysIZE);
    }];
    
}
// 去支付按钮的 方法

- (void)gopayAction {
    !self.GoPayBtnBolck?:self.GoPayBtnBolck();
}

- (void)canleAction {
    [self removeFromSuperview];
}

// 半透明部分手势
- (void)addTheTap {
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(event:)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
}
- (void)event:(UITapGestureRecognizer *)gesture {
    [self removeFromSuperview];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isDescendantOfView:_backView] || [touch.view isDescendantOfView:_goPayBtn] || [touch.view isDescendantOfView:_canleBtn] || [touch.view isDescendantOfView:_titleLabel] || [touch.view isDescendantOfView:_conTextLabel]) {
        // 让其余控件 不响应此事件
        return NO;
    }
    return YES;
}

@end
